package com.seuic.hnjiningposapp.hnapps.ui.view.dialog;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lxj.xpopup.core.BasePopupView;
import com.seuic.hnjiningposapp.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 口头挂失 选择挂失账户
 */
public class LossPp extends BasePopupView {
    Unbinder bind;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    List<Bean> beans = new ArrayList<>();

    private Context mContext;
    LossPpCallBack mLossPpCallBack;

    public LossPp(@NonNull Context context, LossPpCallBack lossPpCallBack) {
        super(context);
        this.mContext = context;
        this.mLossPpCallBack = lossPpCallBack;
    }

    @Override
    protected int getPopupLayoutId() {
        return R.layout.loss_pp;
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
        //注解解绑
        if (bind != null && bind != Unbinder.EMPTY) {
            bind.unbind();
        }
        this.bind = null;
    }

    public void setBeans(List<Bean> beans) {
        this.beans = beans;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        bind = ButterKnife.bind(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        Adapter adapter = new Adapter(R.layout.losspp_item_layout, null);
        recyclerView.setAdapter(adapter);

        recyclerView.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL));



        adapter.setNewData(beans);
    }

    public static class Bean {
        String name;

        public Bean(String name) {
            this.name = name;
        }
    }

    private class Adapter extends BaseQuickAdapter<Bean, BaseViewHolder> {
        public Adapter(int layoutResId, List<Bean> data) {
            super(layoutResId, data);
        }

        @Override
        protected void convert(BaseViewHolder baseViewHolder, Bean bean) {
            TextView num, account, username, item_type, item_state;
            num = baseViewHolder.findView(R.id.item_num);//序号
            account = baseViewHolder.findView(R.id.item_acount);//账户
            username = baseViewHolder.findView(R.id.item_username);//开户金额
            item_type = baseViewHolder.findView(R.id.item_type);//账户类型
            item_state = baseViewHolder.findView(R.id.item_state);//账户状态


            Button btn = baseViewHolder.findView(R.id.loss_btn);//挂失

            btn.setOnClickListener(v -> {
                //根据需求返回数据  这里自己添加一下
                mLossPpCallBack.LossPpCall("");
            });
        }
    }

    public interface LossPpCallBack {
        void LossPpCall(String data);
    }
}
